package com.example.dynamic.cglib;

import com.example.dynamic.aspect.LogForService;
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.InvocationHandler;

public class CglibProxy {
    public Object getProxy(Object target) {
        return Enhancer.create(target.getClass(),
                (InvocationHandler) (proxy, method, args) -> {
                    LogForService log = new LogForService();
                    log.before(method.getName());
                    Object o = method.invoke(target, args);
                    log.after(method.getName());
                    return o;
                });
    }
}
